package com.lagou.serializer;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class JsonSerializer implements Serializer {

    @Override
    public String ObjectToString(Object object) throws IOException {
        return JSON.toJSONString(object);
    }

    @Override
    public <T> T StringToObject(Class<T> clazz, String param) throws IOException {
        return JSON.parseObject(param, clazz);
    }

    @Override
    public byte[] ObjectToByte(Object object) throws IOException {
        return JSON.toJSONBytes(object);
    }

    @Override
    public <T> T ByteToObject(Class<T> clazz, byte[] bytes) throws IOException {
        return JSON.parseObject(bytes, clazz);
    }
}
